package com.sanjiahantang.youjiarole.module.evaluate.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.evaluate.beans.EvaGoodsBean;
import com.sanjiahantang.youjiarole.module.evaluate.beans.GoodsAppraiseInitResponse;
import com.sanjiahantang.youjiarole.module.evaluate.models.IEvaluateModel;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by zy on 2017/10/25.
 */

public class EvaluateModel implements IEvaluateModel {
    //商品评价
    @Override
    public void loadGoodsEvaData(final Context context, Map<String, Object> param, final CallBack<EvaGoodsBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/phone/goodsAppraiseInfo/searchAppraiseForRole",
                param, new BaseDelegate.ResultCallback<EvaGoodsBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(EvaGoodsBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void findGoodsAppraiseForCustomer(final Context context, Map<String, String> param, final CallBack<GoodsAppraiseInitResponse> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/mall/phone/goodsAppraiseInfo/findGoodsAppraiseForRole",
                param, new BaseDelegate.ResultCallback<GoodsAppraiseInitResponse>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsAppraiseInitResponse response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void saveAppraiseForCustomer(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/phone/goodsAppraiseInfo/saveAppraiseForRole",
                param, new BaseDelegate.ResultCallback<GoodsAppraiseInitResponse>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsAppraiseInitResponse response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }
}
